package com.myprinciple.inversion.improve;

/**
 * @author zhupanlin
 * @version 1.0
 * @description: TODO
 * @date 2024/4/10 8:44
 */
public class DependencyInversion {

    public static void main(String[] args) {
        // 客户端无需改变
        Person person = new Person();
        person.receive(new Email());
        
        person.receive(new WeiXin());
    }
    
}

// 定义接口
interface IReceiver {
    public String getInfo();
}

// 增加微信
class WeiXin implements IReceiver{

    @Override
    public String getInfo() {
        return "微信信息：Hello,OK";
    }
}

class Email implements IReceiver{
    @Override
    public String getInfo(){
        return "电子邮件信息：Hello World";
    }
}

// 方式二
class Person{
    // 这里是对接口的依赖
    public void receive(IReceiver receiver){
        System.out.println(receiver.getInfo());
    }
    
}
